package com.yqg.education.service.impl;

import com.yqg.education.entity.Live;
import com.yqg.education.mapper.LiveMapper;
import com.yqg.education.service.ILiveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yqg.education.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * LiveServiceImpl 服务实现类
 * @author 张芸博
 * @since 2025-04-10
 */
@Service
public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements ILiveService {

    @Resource
    private IUserService userService;
    @Resource
    private LiveMapper liveMapper;

    public Map<String, Object>  findStuPage(Integer pageNum, Integer pageSize, String name, Integer typeId, Integer userId,Integer courseId) {
        Integer pageStartNumber = pageNum * pageSize - pageSize;
        List<Long> courseIds = null;
        //app端courseId不是空，网页端courseId为空
        if (courseId == null){
            courseIds = userService.getCourseIdByUserId(userId);
        }
        List<Live> liveList = liveMapper.findStuPage(pageStartNumber, pageSize, name, typeId, courseIds,courseId);
        Long count = liveMapper.findStuCount(name, typeId, courseIds,courseId);
        Map<String, Object> liveMap = new HashMap();
        liveMap.put("records", liveList);
        liveMap.put("total", count);
        return liveMap;
    }

}
